<?php
/**
 * 预购席位
 *
 * @author Alen
 * @since 1.0.0 2013-12-17
 */
class AC_PreorderseatAction extends PyramidUCAction {
    //put your code here
    public function index(){
        if(!$this->USER['TradePassword']) redirect('未设置交易密码','?m=UC_TradePassword_Edit');
                
        $bizacc=new SoBizFinanceAccount();
        $acc=$bizacc->read_one($this->USER_NAME);
        
        $this->assign('num', $this->USER['QuotaNumber']);
        $this->assign('check_pwd', isset($_SESSION['tradepwd']));
        $this->assign('blance', $acc['Blance']);
        $this->display();
    }
    
    public function checkpwd(){
        $this->check_tradepassword();
    }
    
    public function save(){        
	$num=  request_numeric('SeatNumber');
	$rule=array(10=>8,20=>12,30=>16);
	if(!array_key_exists($num,$rule)) redirect('数量无效!');
	$yj=$rule[$num];
        $bizacc=new SoBizFinanceAccount();
        $acc=$bizacc->read_one($this->USER_NAME);
	$amount= 300 * $num;
	$acc['Blance']=$acc['Blance']-$amount;
	if($acc['Blance']<0) redirect('余额不足,请充值!');
        // 预购席位数量=原预购席位数量+新数量
        $bizuser=new SoBizUser();
        $bizuser->update_records(sprintf('QuotaNumber=QuotaNumber+%u, ModifiedTime=\'%s\'',$num,date('Y-m-d H:i:s')),"UserName='$this->USER_NAME'");
        
        // 将预付款从Blance转入AdvancePayment,激活会员的时候再一个一个扣除
       
        $bizacc->add_transaction_for_prevorderseat($this->USER_NAME,$amount);
        // 收到系统支付的促销折扣提成
        $bizacc->add_transaction($this->USER_NAME,($yj*$num),'IN_PREORDER_SEAT_COMMISSION');
	redirect('预购成功');
    }
}
